﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPETwit.Data.Entity;

namespace CPETwit.Data.Manager
{
    public class AbonnementManager
    {
        public void CreateAbonnement(Abonnement a)
        {
            ContextHelper.Context.Abonnement.AddObject(a);
            ContextHelper.Context.SaveChanges();
        }

        public void DeleteAbonnement(Abonnement a)
        {
            ContextHelper.Context.Abonnement.DeleteObject(a);
            ContextHelper.Context.SaveChanges();
        }

        public void UpdateAbonnement(Abonnement a)
        {
            ContextHelper.Context.SaveChanges();
        }

        public IEnumerable<Abonnement> getAllAbonnementsPublisherFromUser(long _id)
        {
            var query = from abonnement in ContextHelper.Context.Abonnement
                        where abonnement.publisher == _id
                        select abonnement;

            return query;
        }

        public IEnumerable<Abonnement> getAllAbonnementsFollowerFromUser(long _id)
        {
            var query = from abonnement in ContextHelper.Context.Abonnement
                        where abonnement.follower == _id
                        select abonnement;

            return query;
        }

        public Abonnement GetAbonnement(long followerId, long publisherId)
        {
            return (from abo in ContextHelper.Context.Abonnement
                    where abo.follower == followerId
                    where abo.publisher == publisherId
                    select abo).FirstOrDefault();
        }
    }
}
